package com.xjc.system.result;

import lombok.Builder;
import lombok.Data;

/**
 * 徐锦程
 * 时间:2024-10-01 15:17
 * 描述:统一返回
 */
@Data
@Builder
public class Result<T> {

    private T data;

    private String message;

    private int code;

    public static  Result ok() {
        return Result.builder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).data(null).build();
    }

    public static  Result ok(String message) {
        return Result.builder().code(ResultCode.SUCCESS.getCode()).message(message).data(null).build();
    }
    public static  Result error() {
        return Result.builder().code(ResultCode.FAIL.getCode()).message(ResultCode.FAIL.getMessage()).data(null).build();
    }

    public static  Result error(String message) {
        return Result.builder().code(ResultCode.FAIL.getCode()).message(message).data(null).build();
    }

    public static  Result error(ResultCode resultCode) {
        return Result.builder().code(resultCode.getCode()).message(resultCode.getMessage()).data(null).build();
    }

    public static <T> Result<T> okWithData(T data) {
        return Result.<T>builder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).data(data).build();
    }

    public static <T>  Result<T> okWithData(ResultCode resultCode,T data) {
        return Result.<T>builder().code(resultCode.getCode()).message(resultCode.getMessage()).data(data).build();
    }
}
